package com.team622.shop.user.service.controller;

import com.team622.shop.common.Result;
import com.team622.shop.user.model.dto.AdminLoginDTO;
import com.team622.shop.user.model.vo.AdminLoginVO;
import com.team622.shop.user.service.service.AdminService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author team622
 * @since 2025-07-15
 */
@Slf4j
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService adminService;

    @Operation(summary = "管理员登录", description = "使用用户名和密码登录管理系统")
    @PostMapping("login")
    public Result<AdminLoginVO> login(
            @Parameter(description = "登录参数", required = true)
            @Valid @RequestBody AdminLoginDTO adminLoginDTO) {
        log.info("adminLoginDTO:{}", adminLoginDTO);
        AdminLoginVO adminLoginVO = adminService.login(adminLoginDTO);
        return Result.success(adminLoginVO);
    }

//    @Operation(summary = "修改管理员密码", description = "修改当前登录管理员的密码")
//    @PutMapping("password")
//    public Result<Void> updatePassword(
//            @Parameter(description = "密码修改参数", required = true)
//            @Valid @RequestBody AdminUpdatePasswordDTO adminUpdatePasswordDTO) {
//        log.info("updatePassword:{}", adminUpdatePasswordDTO);
//        adminService.updatePassword(adminUpdatePasswordDTO);
//        return Result.success();
//    }


    //验证Token
    @GetMapping("checkToken")
    public Result<Boolean> checkToken() {
        boolean checked = adminService.checkToken();
        return Result.success(checked);
    }
}
